<%@ include file="/taglibs.jsp"%>

<head>
    <title>
	    <c:if test="${empty param.id}">
	    	<fmt:message key="groupForm.add.title"/>
	    </c:if>
	    <c:if test="${not empty param.id}">
	    	<fmt:message key="groupForm.edit.title"/>
	    </c:if>
    </title>
</head>


<s:form name="groupForm"  action="saveGroup" method="post" validate="true">
<s:hidden name="group.id" value="%{group.id}"/>

<s:textfield maxlength="50" key="group.name" required="true" size="50"/>
<s:textfield maxlength="200" key="group.description"  size="70"/>
<s:select key="group.authority" 
		list="#{'ROLE_ADMINISTRATOR':'Qu\u1EA3n tr\u1ECB c\u1EA5p cao', 'ROLE_MODERATOR':'\u0110i\u1EC1u ph\u1ED1i vi\u00EAn', 'ROLE_USER':'Ng\u01B0\u1EDDi d\u00F9ng h\u1EC7 th\u1ED1ng'}" 
		name="group.authority" value="group.authority"/>
		
<s:select key="group.label.permission"
         list="lstAllMenu" 
         listValue="name"
         listKey="id"
         name="lstPermissionMenu" 
		 multiple="true" 
		 value="%{lstSelectedMenu.{id}}"
         size="%{lstAllMenu.size()}" />
<tr>
    <td colspan="2">
    	<c:if test="${param.id != 1 || empty param.id}"> 
	    	<s:a href="javascript:void(0)" id="save">
				<img src="${ctx}/images/btn_save_link.png" align="left" >
			</s:a>
		</c:if>
	    <c:if test="${not empty param.id}">
			<c:if test="${param.id != 1}">
		    	<button type="submit" class="button" name="delete" onclick="return confirm('<fmt:message key="message.delete.confirm"></fmt:message>')">
					<fmt:message key="button.delete.title"></fmt:message>
					<img src="${ctx}/images/btn_delete.png" align="left" height="20" width="20">
				</button>
			</c:if>
    	</c:if>
        <button type="submit" class="button" name="cancel" onclick="form.onsubmit=null">
			<fmt:message key="button.cancel.title"></fmt:message>
			<img src="${ctx}/images/btn_cancel.png" align="left" height="20" width="20">
		</button>
		
    </td>
</tr>

</s:form>


    <script type="text/javascript">
    
    $('#save').click(function(){
		$.blockUI({ message: ajaxAnimation });
		$.ajax({
		  type: 'POST',
		  url: $('form').attr('action') + '?struts.enableJSONValidation=true&struts.validateOnly=true',
		  data: $('form').serialize(),
		  success: function(data){
			 var errorsObject = $.StrutsUtils.getValidationErrors(data);
			 if(errorsObject.fieldErrors) {
		       	//StrutsUtils.showValidationErrors(form, errorsObject);
				 $.StrutsUtils.showValidationErrors($('form'), errorsObject);
		     } else if(errorsObject.errors) {
		       	//StrutsUtils.showValidationErrors(form, errorsObject);
				 $.StrutsUtils.showValidationErrors($('form'), errorsObject);
		     } else {
		       //good to go, regular submit
		       $('form').submit();
		     }
		  },
		  dataType: "text/html"
		});
	});

    
    </script>
